package com.ma.workorder.audioManager;



import android.Manifest;
import android.annotation.SuppressLint;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;



import com.ma.R;
import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.PermissionYes;

import java.util.List;

import utils.ConstantUtil;

public class ExampleActivity extends AppCompatActivity {
    private AudioRecordButton mEmTvBtn;




    @SuppressLint("WrongViewCast")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_example);
        mEmTvBtn =  findViewById(R.id.em_tv_btn);

        boolean isWriteFile= ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED;
        boolean isAudio= ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED;
        if (isWriteFile ||isAudio) {
            AndPermission.with(this)
                    .requestCode(101)
                    .permission(Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.RECORD_AUDIO)
                    .send();

        }else {
            mEmTvBtn.setAudioFinishRecorderListener(new AudioRecordButton.AudioFinishRecorderListener() {
                @Override
                public void onFinished(float seconds, String filePath) {
                    Record recordModel = new Record();
                    recordModel.setSecond((int) seconds <= 0 ? 1 : (int) seconds);
                    recordModel.setPath(filePath);
                    recordModel.setPlayed(false);

                }
            });
        }

    }

    //6.0
    @PermissionYes(ConstantUtil.permission_code_cam)
    private void permissionYes() {



    }






    @Override
    protected void onPause() {
        MediaManager.release();//保证在退出该页面时，终止语音播放
        super.onPause();
    }


}
